<template>
    <fieldset>
        <legend>登入页面</legend>
        用户名：
        <input type="text" v-model="username">
        <br>
        密码：
        <input type="password" v-model="password" @keydown.enter="Login">
        <br>
        <button @click="Login">登入</button>
    </fieldset>
</template>

<script setup>
import * as  api from "../../api/users"
import { ref } from 'vue'
import { useRouter } from "vue-router"
// 1.获取输入框的值

let username = ref('')
let password = ref('')

// 2.发送请求

let router = useRouter()

let Login = async () => {
    let res = await api.loginApi(username.value, password.value)
    console.log(res);

    if (res.data.state) {
        // 设置 token 存储
        sessionStorage.setItem('data', res.data.token)
        // 跳转页面
        router.push('/')
    }else{
        alert(res.data.msg)
    }
}

    // 3.判断状态
</script>

